<template>
	<view class="com-order-container">
		<cu-custom v-if="level>1" bgColor="bg-white" :isBack="true" :isBackClick="true" @back-click="backHandle"><block slot="backText" ><text class="text-bold">返回上一级</text></block></cu-custom>
		<view class="base-border-bt1"></view>
		<view class="padding-lr">
			<view class="flex align-center barItem" v-for="(item,index) in dataList" :key="index" @click="titleHandle(item.id)">
				<text class="cuIcon-title" :class="titleColor[level-1]"></text>
				<view class="padding-left-15 base-font-32 text-333">{{item.name}}</view>
			</view>
		</view>
		
		
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import api from '@/utils/api.js';
	import siteApi from '@/utils/siteApi.js';
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				reload: '',
				parentId:'',
				dataList: [],
				level:1,
				nextParentId:'',
				isBack:false,
				titleColor:['text-green','text-orange','text-blue','text-purple'],
				backHandleBtn:false

			}
		},
		onShow(options) {
			let _slef=this;
			_slef.isBack=uni.getStorageSync("isBack")
			if(_slef.isBack){
				uni.removeStorage({
					key: 'isBack'
				});
				_slef.level = uni.getStorageSync('level') || 1;
				_slef.parentId= uni.getStorageSync('parentId');
				uni.removeStorage({
					key: 'level'
				});
				uni.removeStorage({
					key: 'parentId'
				});
				_slef.backHandleBtn=true
			}
			else{
				_slef.level=1,
				_slef.parentId=''
				_slef.backHandleBtn=false
			}
			_slef.initData(this.parentId);
			
			
		},
		onLoad: function(options) {
			api.acceptShare(1, options);
		},
		methods: {
			initData: function(id) {
				let _self = this;
				this.dataList=[]
				siteApi.selectWxNoticeCategoryList({parentId:id,level:_self.level}).then(res=>{
					if(res.data.length>0){
						uni.setStorageSync('level', _self.level);
						uni.setStorageSync('parentId', id);
						if( !_self.backHandleBtn){
							uni.setStorageSync('nextParentId', _self.nextParentId);
						}
						
						res.data.forEach((item,index)=>{
							this.dataList.push(item)
						})
					}else{
						
						uni.navigateTo({
							url:'/pages/index/list?id='+id
						})
					}
				})
			},
			titleHandle(id){
				this.nextParentId=this.parentId+''
				this.parentId=id
				this.level++;
				this.initData(id)
			},
			backHandle(){
				this.level--
				if(this.level===1){
					this.parentId=''
				}
				else{
					this.parentId=uni.getStorageSync('nextParentId');
				}
				
				this.initData(this.parentId)
			}
			
		}
		
	}
</script>

<style scoped lang="scss">
	
	@import "../../static/css/variables.scss";
	.com-order-container{
		.barItem{border-bottom:1rpx solid #eee;padding:25rpx 0}
		.padding-left-15{padding-left:15rpx;}
		background: #FFFFFF;min-height:100vh;
		
		
	}
</style>